package com.shazhu.web.controller.nongjt;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shazhu.common.annotation.Log;
import com.shazhu.common.core.controller.BaseController;
import com.shazhu.common.core.domain.AjaxResult;
import com.shazhu.common.enums.BusinessType;
import com.shazhu.nongjt.domain.NjtInspectionRecord;
import com.shazhu.nongjt.service.INjtInspectionRecordService;
import com.shazhu.common.utils.poi.ExcelUtil;
import com.shazhu.common.core.page.TableDataInfo;

/**
 * 检查记录Controller
 * 
 * @author shazhu
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/nongjt/record")
public class NjtInspectionRecordController extends BaseController
{
    @Autowired
    private INjtInspectionRecordService njtInspectionRecordService;

    /**
     * 查询检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtInspectionRecord njtInspectionRecord)
    {
        startPage();
        List<NjtInspectionRecord> list = njtInspectionRecordService.selectNjtInspectionRecordList(njtInspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:export')")
    @Log(title = "检查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtInspectionRecord njtInspectionRecord)
    {
        List<NjtInspectionRecord> list = njtInspectionRecordService.selectNjtInspectionRecordList(njtInspectionRecord);
        ExcelUtil<NjtInspectionRecord> util = new ExcelUtil<NjtInspectionRecord>(NjtInspectionRecord.class);
        util.exportExcel(response, list, "检查记录数据");
    }

    /**
     * 获取检查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(njtInspectionRecordService.selectNjtInspectionRecordById(id));
    }

    /**
     * 新增检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:add')")
    @Log(title = "检查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtInspectionRecord njtInspectionRecord)
    {
        return toAjax(njtInspectionRecordService.insertNjtInspectionRecord(njtInspectionRecord));
    }

    /**
     * 修改检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:edit')")
    @Log(title = "检查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NjtInspectionRecord njtInspectionRecord)
    {
        return toAjax(njtInspectionRecordService.updateNjtInspectionRecord(njtInspectionRecord));
    }

    /**
     * 删除检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:record:remove')")
    @Log(title = "检查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(njtInspectionRecordService.deleteNjtInspectionRecordByIds(ids));
    }
}
